package com.mymorningroutine;
import android.util.*;
import android.content.*;
import java.util.*;

public class MyBroadcastReceiver extends BroadcastReceiver
{

	private String TAG = "MyBroadcastReceiver";

	

		public MyBroadcastReceiver(){}


	@Override
	public void onReceive(Context context, Intent intent)
	{            
		if (intent.getExtras() != null)
		{
			boolean finished = intent.getBooleanExtra("finished", true);

			if (!finished)
			{
				long millisUntilFinished = intent.getLongExtra("countdown", 0);
			
				Calendar cal = Calendar.getInstance();
				Date current = cal.getTime();
				AlarmStatusActivity.setTimeText(current.getHours() + ":" + (current.getMinutes() < 10 ?  "0" + current.getMinutes() : current.getMinutes()) + ":" + (current.getSeconds() < 10 ?  "0" + current.getSeconds() : current.getSeconds()));
				cal.setTimeInMillis(millisUntilFinished);
				Date d = cal.getTime();	

				AlarmStatusActivity.setCountDownText(d.getMinutes() + ":" + (d.getSeconds() < 10 ?  "0" + d.getSeconds() : d.getSeconds()));
				AlarmStatusActivity.mNotifyBuilder.setContentText(d.getMinutes() + ":" + (d.getSeconds() < 10 ?  "0" + d.getSeconds() : d.getSeconds()));
				AlarmStatusActivity.mNotificationManager.notify(
					AlarmStatusActivity.notifyID,
					AlarmStatusActivity.mNotifyBuilder.build());

				            
			}
			else
			{
				boolean music = intent.getBooleanExtra("music", false);
				if(music){
					AlarmStatusActivity.endMusic(context);
					

				}else{
					AlarmStatusActivity.startMusic(context);
					
				}

			}
		}
	}
}
